<?
/*! \brief Base class for backend controller.
 * 
 */
class BaseServiceController extends Zend_Controller_Action
{
	public $_service, $_validator, $_method, $_db;
	
	/*! \brief Executed by Zend_Controller_Action before dispatch.
	 * 
	 * Sets, or retrieves from Zend_Registry, some commonly used variables 
	 * (e.g., database), the default content-header (text/xml), creates a 
	 * Service, a Validator and forwards the request to 
	 * ServiceController::indexAction().
	 */
	function init() 
	{
		/* Services are typically returning XML, however do return files which 
		 * will be dealt with on a case-by-case basis
		 */
		$this->getResponse()->setHeader('Content-Type', 'text/xml');
		
		$this->_method = $this->getRequest()->getActionName();		
		
		//If the method exists, let's make a service object and the validator
		if(Service::exists($this->_method)) 
		{
			$this->_service = new Service($this->_method);
			$this->_validator = new Validator($this->_service, 
				$this->getRequest()->getPost());
		}
		
		//Get the database
		$this->_db = Zend_Registry::get('db');
		
		//Go immediately to index
		$this->indexAction();
	}
}